-
Notifications
You must be signed in to change notification settings - Fork 432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should solve integer overflows in SAPT code #619
Conversation
Should prevent integer overflow. May not be exhaustive though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Jerome, these look great.
Im not sure were we could fish up a box that has the ~130GB of space to test things out. We could just try banging on virtual memory.
@@ -620,7 +620,7 @@ void SAPT2::ijkl_to_ikjl(double *tARAR, int ilength, int jlength, int klength, | |||
|
|||
for(int i=0; i<ilength; i++) { | |||
for(int l=0; l<llength; l++) { | |||
long int ijkl = i*jlength*klength*llength + l; | |||
long int ijkl = (long int)i*jlength*klength*llength + l; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might remember wrong, but don't you need to also cast jlength, klength and llength, since the order of evaluation isn't guaranteed...? What this is doing is typecasting i to long int, but jlengthklengthllength is still int and might overflow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, the compiler should promote all of the operands to long int before the multiplication takes place.
@@ -240,7 +240,7 @@ void SAPT2p::r_ccd_prep(const char *TARBS, const char *ARBS, const char *CA_RBS, | |||
|
|||
double **tARBS = block_matrix(occA*virA,occB*virB); //! | |||
|
|||
C_DCOPY(occA*virA*occB*virB,&(vARBS[0][0]),1,&(tARBS[0][0]),1); | |||
C_DCOPY((size_t)occA*virA*occB*virB,&(vARBS[0][0]),1,&(tARBS[0][0]),1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing here.
@jgonthier These are good changes regardless, so pulling them in now. If it turns out it didn't fix the problem we can always go back in later. |
Description
Substitute some int by size_t, and introduces (size_t) casts wherever multiplication of integers seemed problematic.
Todos
Questions
Status